/******************************************************
 Project:				PCSync
 Author:				jean-philippe
 File name:				DirectoryParser.java
 Date created:			Aug 25, 2012
 Date last modified:	Aug 25, 2012
 *******************************************************
 Modification History
 *******************************************************
 Aug 25, 2012		Initial version.
 ******************************************************/
package pcsync.client;

import java.io.IOException;
import java.nio.file.FileVisitResult;
import java.nio.file.FileVisitor;
import java.nio.file.Path;
import java.nio.file.attribute.BasicFileAttributes;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

import org.apache.log4j.Logger;

/**
 * @author jean-philippe
 *
 */
public class FileLoader implements FileVisitor<Path> 
{
	Logger logger;
	
	public FileLoader()
	{
		logger = Logger.getLogger(this.getClass().getCanonicalName());
	}
	
	@Override
	public FileVisitResult postVisitDirectory(Path path, IOException ioexception) throws IOException
	{
		return FileVisitResult.CONTINUE;
	}

	@Override
	public FileVisitResult preVisitDirectory(Path path, BasicFileAttributes ioexception) throws IOException
	{
		System.out.println("dir: " + path.getFileName().toString());
		return FileVisitResult.CONTINUE;
	}

	@Override
	public FileVisitResult visitFile(Path path, BasicFileAttributes ioexception) throws IOException
	{
		System.out.println("file: " + path.getFileName().toString());
		try
		{
			MessageDigest md5 = MessageDigest.getInstance("MD5");
			// TODO
		}
		catch (NoSuchAlgorithmException e)
		{
			logger.error("MD5 algorithm used for hashing does not exist");
			e.printStackTrace();
		}
		
		return FileVisitResult.CONTINUE;
	}

	@Override
	public FileVisitResult visitFileFailed(Path path, IOException ioexception) throws IOException
	{
		return FileVisitResult.CONTINUE;
	}
}